<template>
    <div>
        <div v-html="detailData.goods_introduce"></div>
        <van-action-bar>
            <van-action-bar-icon icon="chat-o" text="客服" />
            <van-action-bar-icon icon="cart-o" text="购物车" />
            <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
            <van-action-bar-button type="warning" @click="addCart" text="加入购物车" />
            <van-action-bar-button type="danger" text="立即购买" />
        </van-action-bar>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';
const router =new useRouter();
const route =new useRoute();
const detailData = ref([]);
import { detailApi } from '@/api/api';
detailApi(route.params.goods_id).then((res) => {
    console.log(res);
    detailData.value = res.data.message;
})
import { useCounterStore } from '@/stores/cart'
// 可以在组件中的任意位置访问 `store` 变量 ✨
const store = useCounterStore()
const addCart=()=>{
    const token=localStorage.getItem('token');
    if(!token){
        router.push('/login');
    }
    else{
        store.addCart(detailData.value,route.params.goods_id);
        router.push('/index/cart');
    }
}

</script>

<style lang="scss" scoped></style>